<?php

	if (!class_exists('shopPage'))
	 {
		 $include_dir =  ((!defined('SHOP_DEVELOPER') || !constant('SHOP_DEVELOPER')) && version_compare(PHP_VERSION,'5.0','>=')?'include_v5':'include');
		 require_once(CORE_DIR.'/'.$include_dir.'/shopPage.php');
	 }

	 class shop_diamond extends shopPage
	 {
		 var $noCache = true;

		 function shop_diamond()
		 {
			 parent::shopPage();
		 }

		 function chooceEndstone($id,$page=1)
		 {
			 if (!$id)
			 {
				 $this->begin($_SERVER['HTTP_REFERER']);
				 trigger_error(__('参数错误'),E_USER_ERROR);
				 $this->end();
				 exit;
			 }
			 $this->title="钻石定制步骤二";
			 $this->pagedata['bare_id'] = $id;
			 $objProduct = &$this->system->loadModel('goods/products');
			 $objDiamondCat = &$this->system->loadModel('plugins/diamond/diamondCat');
			 $aDisabledCat = $objDiamondCat->getDisabledCat();
			 $filter['cat_id'] = $aDisabledCat;
			 $pageLimit = $this->system->getConf('gallery.display.listnum');
			 $aProduct = $objProduct->getList(null,$filter,$pageLimit*($page-1),$pageLimit,$orderby);
			 $this->pagedata['products'] = $aProduct;
			 $count = $objProduct->count($filter);
			 $this->pagedata['pager'] = array(
					'current'=>$page,
					'total'=>ceil($count/$pageLimit),
					'link'=>$this->system->mkUrl('action_diamond','chooceEndstone',array($id,($tmp = time()))),
					'token'=>$tmp
				);
			 $this->pagedata['_MAIN_'] = dirname(__FILE__).'/view/shop/diamond/chooceEndstone.html';
			//$this->__tmpl = dirname(__FILE__).'/view/shop/diamond/chooceEndstoneTmpl.html';
			 $this->output();
		 }
		
		 /**
		  * 此函数暂时禁用
		  * 作为中转用
		  *
		  */
		 function doChoose()
		 {
			 $_POST['diamond']['bare_id'] = 62;
			 $_POST['diamond']['goods_id'] = 78;
			 if (!($_POST['diamond']['bare_id'] && $_POST['diamond']['goods_id']))
			 {
				 $this->begin($_SERVER['HTTP_REFERER']);
				 trigger_error(__('参数提交错误'),E_USER_ERROR);
				 $this->end();
				 exit;
			 }
			 $bare = $_POST['diamond']['goods_id'].'@'.$_POST['diamond']['bare_id'];
			 $this->system->setcookie('BARE_'.$_POST['diamond']['goods_id'],$_POST['diamond']['bare_id']);
			 header('Location: '.$this->system->mkUrl('product','index',array($_POST['diamond']['goods_id'])));
		 }
	 }
?>